using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UIHealthbarController:MonoBehaviour {

	[SerializeField] HealthBar targetHealtBar;
	[SerializeField] float pixelPerHp;
	[SerializeField] TextMeshProUGUI text;
	RectTransform rectTransform;

	private void OnEnable() {
		targetHealtBar.mob=Player.instance;
		rectTransform=GetComponent<RectTransform>();
	}

	private void Update() {
		if(Player.instance) targetHealtBar.mob=Player.instance;
		Vector2 sizeCurrent = rectTransform.sizeDelta;
		sizeCurrent.x=Player.instance._maxHP*pixelPerHp+4;

		rectTransform.sizeDelta=sizeCurrent;
		text.text=$"{Mathf.CeilToInt(Player.instance.HP)}/{Mathf.CeilToInt(Player.instance._maxHP)}";
	}

}
